package cn.campsg.messageboard.model;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

public class Message {
    private Integer id;
    private Integer userId; // 发布者的用户ID
    private String content;
    private Timestamp createdAt;
    private Integer parentId; // 父评论ID，0表示顶级评论
    private Integer likeCount; // 点赞数
    private Integer status; // 状态：0-正常, 1-已删除, 2-管理员屏蔽中
    private User user; // 发布者信息
    private List<Message> replies = new ArrayList<>();

    // 无参构造函数
    public Message() {}
    // 全参数构造函数
    public Message(Integer id, Integer userId, String content, Timestamp createdAt, Integer parentId, Integer likeCount, Integer status) {
        this.id = id;
        this.userId = userId;
        this.content = content;
        this.createdAt = createdAt;
        this.parentId = parentId;
        this.likeCount = likeCount;
        this.status = status;
    }

    public Message(Integer id, Integer userId, String content, Integer parentId){
        this.id = id;
        this.userId = userId;
        this.content = content;
        this.parentId = parentId;
        this.createdAt = new Timestamp(System.currentTimeMillis());
        this.likeCount = 0; // 默认点赞数为0
        this.status = 0; // 默认状态为正常
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Timestamp getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Timestamp createdAt) {
        this.createdAt = createdAt;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public Integer getLikeCount() {
        return likeCount;
    }

    public void setLikeCount(Integer likeCount) {
        this.likeCount = likeCount;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Message> getReplies() {
        return replies;
    }
    public void setReplies(List<Message> replies) { this.replies = replies; }

    @Override
    public String toString() {
        return "Message{" +
                "id=" + id +
                ", userId=" + userId +
                ", content='" + content + '\'' +
                ", createdAt=" + createdAt +
                ", parentId=" + parentId +
                ", likeCount=" + likeCount +
                ", status=" + status +
                '}';
    }

    public void setUsername(String username) {
        if (this.user == null) {
            this.user = new User();
        }
        this.user.setUsername(username);
    }
}
